/*     */ package system.staros.sblock1;
/*     */ 
/*     */ import java.io.BufferedReader;
/*     */ import java.io.File;
/*     */ import java.io.FileReader;
/*     */ import java.io.IOException;
/*     */ import java.io.Reader;
/*     */ import java.io.StringReader;
/*     */ import java.util.HashMap;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ 
/*     */ public class Interpreter
/*     */ {
/*  46 */   private Map<String, ZemObject> symbolTable = new HashMap();
/*     */ 
/*     */   public Interpreter()
/*     */   {
/*  54 */     this.symbolTable.put("print", new PrintFunction());
/*  55 */     this.symbolTable.put("println", new PrintLineFunction());
/*  56 */     this.symbolTable.put("len", new LenFunction());
/*  57 */     this.symbolTable.put("array_push", new ArrayPushFunction());
/*     */   }
/*     */ 
/*     */   public ZemObject getVariable(String paramString, SourcePosition paramSourcePosition)
/*     */   {
/*  68 */     if (!this.symbolTable.containsKey(paramString)) {
/*  69 */       throw new UnsetVariableException(paramString, paramSourcePosition);
/*     */     }
/*  71 */     return (ZemObject)this.symbolTable.get(paramString);
/*     */   }
/*     */ 
/*     */   public void setVariable(String paramString, ZemObject paramZemObject)
/*     */   {
/*  81 */     this.symbolTable.put(paramString, paramZemObject);
/*     */   }
/*     */ 
/*     */   public void checkFunctionExists(String paramString, SourcePosition paramSourcePosition)
/*     */   {
/*  90 */     ZemObject localZemObject = getVariable(paramString, paramSourcePosition);
/*  91 */     if (!(localZemObject instanceof Function))
/*  92 */       throw new InvalidTypeException(paramString + " is not a function", paramSourcePosition);
/*     */   }
/*     */ 
/*     */   public ZemObject callFunction(String paramString, List<ZemObject> paramList, SourcePosition paramSourcePosition)
/*     */   {
/* 104 */     Function localFunction = (Function)this.symbolTable.get(paramString);
/*     */ 
/* 106 */     HashMap localHashMap = new HashMap(this.symbolTable);
/*     */ 
/* 109 */     int i = 0;
/* 110 */     int j = 0;
/* 111 */     for (int k = 0; 
/* 112 */       k < localFunction.getParameterCount(); k++) {
/* 113 */       String str = localFunction.getParameterName(k);
/* 114 */       ZemObject localZemObject2 = localFunction.getDefaultValue(k);
/* 115 */       if (localZemObject2 == null) {
/* 116 */         j++;
/*     */       }
/* 118 */       if (k < paramList.size())
/*     */       {
/* 120 */         localZemObject2 = (ZemObject)paramList.get(k);
/*     */       }
/* 122 */       if (localZemObject2 == null) {
/* 123 */         i++;
/*     */       }
/* 125 */       setVariable(str, localZemObject2);
/*     */     }
/* 127 */     if (i > 0) {
/* 128 */       throw new TooFewArgumentsException(paramString, j, paramList.size(), paramSourcePosition);
/*     */     }
/*     */ 
/* 131 */     ZemObject localZemObject1 = localFunction.eval(this, paramSourcePosition);
/*     */ 
/* 133 */     this.symbolTable = localHashMap;
/*     */ 
/* 135 */     return localZemObject1;
/*     */   }
/*     */ 
/*     */   public ZemObject eval(String paramString)
/*     */     throws IOException
/*     */   {
/* 146 */     return eval(new StringReader(paramString));
/*     */   }
/*     */ 
/*     */   public ZemObject eval(File paramFile)
/*     */     throws IOException
/*     */   {
/* 157 */     return eval(new BufferedReader(new FileReader(paramFile)));
/*     */   }
/*     */ 
/*     */   public ZemObject eval(Reader paramReader)
/*     */     throws IOException
/*     */   {
/* 168 */     Lexer localLexer = new Lexer(paramReader);
/* 169 */     Parser localParser = new Parser(localLexer);
/* 170 */     RootNode localRootNode = localParser.program();
/* 171 */     return localRootNode.eval(this);
/*     */   }
/*     */ }

/* Location:           D:\Марк\!IMPORTANT\staros\archive\version-2.260.zip
 * Qualified Name:     system.staros.sblock1.Interpreter
 * JD-Core Version:    0.6.1
 */